Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ide target component types #6126

Merged
merged 9 commits into from
May 24, 2023

Conversation

philderbeast
Copy link
Contributor

@philderbeast philderbeast commented May 22, 2023

  • Any changes that could be relevant to users have been recorded in ChangeLog.md.
  • The documentation has been updated, if necessary

In a project (stack.yaml) with hundreds of packages I want a quick way to list test suites only.

$ ~/.local/bin/stack ide targets --help
Usage: stack ide targets [--exes] [--tests] [--benchmarks] [--stdout] 
                         [--setup-info-yaml URL] [--snapshot-location-base URL] 
                         [--help]

  List all available Stack targets.

Available options:
  --exes                   List exes (list with --tests and --benchmarks). The
                           default is to list every target but you can use
                           --exes with --tests and --benchmarks to limit the
                           output to 1, 2 or 3 of these component types.
  --tests                  List tests (list with --exes and --benchmarks).
  --benchmarks             List benchmarks (list with --exes and --tests).
  --stdout                 Send output to the standard output stream instead of
                           the default, the standard error stream.
  --setup-info-yaml URL    Alternate URL or path (relative or absolute) for
                           Stack dependencies.
  --snapshot-location-base URL
                           The base location of LTS/Nightly snapshots.
  --help                   Show this help text.

Command 'stack --help' for global options that apply to all subcommands.

I used cabal for this demo because it has way more components (but not yet hundreds):

$ ~/.local/bin/stack ide targets
Cabal:lib
Cabal-QuickCheck:lib
Cabal-described:lib
Cabal-syntax:lib
Cabal-tests:test:check-tests
Cabal-tests:test:custom-setup-tests
Cabal-tests:test:hackage-tests
Cabal-tests:test:no-thunks-test
Cabal-tests:test:parser-tests
Cabal-tests:test:rpmvercmp
Cabal-tests:test:unit-tests
Cabal-tree-diff:lib
cabal-benchmarks:test:cabal-benchmarks
cabal-install:lib
cabal-install:exe:cabal
cabal-install:test:integration-tests2
cabal-install:test:long-tests
cabal-install:test:mem-use-tests
cabal-install:test:unit-tests
cabal-install-solver:lib
cabal-install-solver:test:unit-tests
cabal-testsuite:lib
cabal-testsuite:exe:cabal-tests
cabal-testsuite:exe:setup
solver-benchmarks:lib
solver-benchmarks:exe:hackage-benchmark
solver-benchmarks:test:unit-tests

$ ~/.local/bin/stack ide targets --exes
cabal-install:exe:cabal
cabal-testsuite:exe:cabal-tests
cabal-testsuite:exe:setup
solver-benchmarks:exe:hackage-benchmark

$ ~/.local/bin/stack ide targets --benchmarks

$ ~/.local/bin/stack ide targets --tests
Cabal-tests:test:check-tests
Cabal-tests:test:custom-setup-tests
Cabal-tests:test:hackage-tests
Cabal-tests:test:no-thunks-test
Cabal-tests:test:parser-tests
Cabal-tests:test:rpmvercmp
Cabal-tests:test:unit-tests
cabal-benchmarks:test:cabal-benchmarks
cabal-install:test:integration-tests2
cabal-install:test:long-tests
cabal-install:test:mem-use-tests
cabal-install:test:unit-tests
cabal-install-solver:test:unit-tests
solver-benchmarks:test:unit-tests

$ ~/.local/bin/stack ide targets --tests --exes
Cabal-tests:test:check-tests
Cabal-tests:test:custom-setup-tests
Cabal-tests:test:hackage-tests
Cabal-tests:test:no-thunks-test
Cabal-tests:test:parser-tests
Cabal-tests:test:rpmvercmp
Cabal-tests:test:unit-tests
cabal-benchmarks:test:cabal-benchmarks
cabal-install:exe:cabal
cabal-install:test:integration-tests2
cabal-install:test:long-tests
cabal-install:test:mem-use-tests
cabal-install:test:unit-tests
cabal-install-solver:test:unit-tests
cabal-testsuite:exe:cabal-tests
cabal-testsuite:exe:setup
solver-benchmarks:exe:hackage-benchmark
solver-benchmarks:test:unit-tests

@philderbeast
Copy link
Contributor Author

Related to this question about listing test suites. Cabal doesn't have this yet. I used one of the suggested workarounds but this feature would be nice to have (and a small addition to stack ide targets).

@mpilgrem
Copy link
Member

@philderbeast, thanks. Looks like a good idea to me, but I would organise the help text differently, as follows:

$ ~/.local/bin/stack ide targets --help
Usage: stack ide targets [--exes] [--tests] [--benches] [--stdout] 
                         [--setup-info-yaml URL] [--snapshot-location-base URL] 
                         [--help]

  List Stack targets - all available are listed unless one or more flags are used
  to choose components.

Available options:
  --exes                   List executable targets.
  --tests                  List test suite targets.
  --benches                List benchmark targets.
  --stdout                 Send output to the standard output stream instead of
                           the default, the standard error stream.
  --setup-info-yaml URL    Alternate URL or path (relative or absolute) for
                           Stack dependencies.
  --snapshot-location-base URL
                           The base location of LTS/Nightly snapshots.
  --help                   Show this help text.

Command 'stack --help' for global options that apply to all subcommands.

That is, I would lift the description of the default into the description of the command and take it out of the --exes flag. I would also call the --benchmarks flag --benches, as that would be consistent with the abbreviation used by Stack elsewhere.

I wondered if the boolean logic of the compTypes function could be expressed more succinctly. For example:

compTypes :: (Bool, Bool, Bool) -> NamedComponent -> Bool
compTypes (False, False, False) = const True
compTypes (exes, tests, benches) = \x -> (exes && isCExe x) || (tests && isCTest x) || (benches && isCBench x)

@mpilgrem
Copy link
Member

@philderbeast, is there a reason that there is no --libs flag for library targets?

@philderbeast
Copy link
Contributor Author

philderbeast commented May 24, 2023

is there a reason that there is no --libs flag for library targets?

Yes, I wanted a listing of test suite targets myself and could imagine wanting other runnable component types. I didn't want to add --libs unless someone asked for that and I didn't want to tackle the variations on library components.

@philderbeast philderbeast force-pushed the add/ide-target-comp-types branch from 5983db8 to 3486928 Compare May 24, 2023 12:19
@philderbeast
Copy link
Contributor Author

One thing worth checking is pluralisation. Should the flag be --exe or --exes? The component type is exe but we want as many as there are in a listing so we want --exes as the flag, don't we? I think cabal does the same, exe is the component type but you can target all:exes.

@mpilgrem
Copy link
Member

@philderbeast, on pluralisation, I thought --exes etc was better than --exe etc.

@mpilgrem mpilgrem merged commit 0e64fab into commercialhaskell:master May 24, 2023
@mpilgrem
Copy link
Member

@philderbeast, thanks. I've merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants